package com.allen.apollo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
  * @Description:远程调用设置
  * @Version v1.0.0
  * @author Administrator
  * @date 2022/5/22 19:43
  */
@Configuration
public class RemoteCallConfig {

    @Bean
    public RestTemplate restTemplate(@Autowired ClientHttpRequestFactory requestFactory){
        return new RestTemplate(requestFactory);
    }

    @Bean
    public ClientHttpRequestFactory requestFactory(){
        SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        //读取超时时间
        simpleClientHttpRequestFactory.setReadTimeout(5000);
        //链接超时时间
        simpleClientHttpRequestFactory.setConnectTimeout(15000);
        return simpleClientHttpRequestFactory;
    }
}

